Skip to content

feat(cli): add project memory integration#11364

Open
johnnyeric wants to merge 2 commits into
johnnyeric/memory-core-safetyfrom
johnnyeric/memory-cli-integration
Open

feat(cli): add project memory integration#11364
johnnyeric wants to merge 2 commits into
johnnyeric/memory-core-safetyfrom
johnnyeric/memory-cli-integration

Conversation

@johnnyeric

@johnnyeric johnnyeric commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Issue

No linked issue. Follow-up CLI integration PR stacked on #11355.

Context

#11355 adds the core project memory package. This PR wires that package into the CLI so project memory is available from the TUI, agent prompts, server API, SDK, and Kilo-specific tools.

The goal is to keep the reusable memory implementation in the base PR while making the CLI consume it through Kilo-owned integration points where possible.

Implementation

  • Registers memory services in the CLI runtime and exposes project-memory operations through Kilo HTTP API handlers.
  • Adds TUI memory surfaces, including memory commands, sidebar/meta display, capture events, and a dialog for memory review/interaction.
  • Adds memory_save and memory_recall tools plus prompt/tool-registry integration so agents can persist and retrieve project context.
  • Threads memory context into session prompt construction and system prompt behavior, while keeping most new code under packages/opencode/src/kilocode/.
  • Regenerates SDK/OpenAPI output for the new memory endpoints.
  • Adds focused CLI tests for memory capture, core flows, commands, HTTP API behavior, and memory tools.
  • Includes a patch changeset for user-facing CLI memory support.

Reviewer attention

  • this PR intentionally has small shared-file touch points for runtime registration, session prompt integration, server route wiring, and tool registry wiring.
  • Most behavior is isolated in Kilo-owned paths to reduce upstream merge friction.
  • Large part of the change diff is from generated files
  • I opted for keeping the kilo-memory package lightweight and effect free, and added an "adapter" layer in kilocode path for memory with effect

Screenshots / Video

Screenshot 2026-06-18 at 19 43 13 Screenshot 2026-06-18 at 19 44 24

How to Test

Manual/local verification

Agent verification performed:

  • git push -u origin johnnyeric/memory-cli-integration ran the pre-push hook.
  • Pre-push hook executed bun turbo typecheck successfully across the workspace.

Reviewer test steps

  1. Check out this branch with feat: add core project memory package #11355 as the base branch.
  2. From packages/opencode/, run the focused memory tests, for example bun test ./test/kilocode/memory/memory-core.test.ts ./test/kilocode/memory/memory-capture.test.ts ./test/kilocode/memory/memory-save-tool.test.ts ./test/kilocode/memory/memory-recall-tool.test.ts ./test/kilocode/server/httpapi-memory.test.ts.
  3. Start the CLI TUI and verify the memory command/dialog can open from a project session.
  4. Exercise an agent turn that saves a project memory, then verify a later turn can recall that memory through the memory tools/context.
  5. If reviewing API behavior, run the local backend and inspect the new memory endpoints exposed through the regenerated SDK/OpenAPI output.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Depends on #11355.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b97010a604

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/opencode/src/kilocode/tool/memory-recall.ts Outdated
Comment thread packages/opencode/src/kilocode/memory/service.ts
Comment thread packages/opencode/src/kilocode/system-prompt.ts Outdated
Comment thread packages/opencode/src/session/prompt.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

No new issues in the incremental diff since 9713ad96bd7d9a9c74bbb893d0ecb42dec1bb4b9.

Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
packages/kilo-memory/src/capture/redact.ts 48 Bare user@host URLs now trip the secret detector, so harmless clone/remote URLs can no longer be saved into memory.
packages/kilo-memory/src/recall/budget.ts 60 The truncation note tells agents to use mode=typed, which cannot recover omitted session digests from a truncated startup index.
Files Reviewed (1 file)
  • packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx

Fix these issues in Kilo Cloud

Previous Review Summaries (4 snapshots, latest commit 9713ad9)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 9713ad9)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-memory/src/capture/redact.ts 48 Bare user@host URLs now trip the secret detector, so harmless clone/remote URLs can no longer be saved into memory.
packages/kilo-memory/src/recall/budget.ts 60 The truncation note tells agents to use mode=typed, which cannot recover omitted session digests from a truncated startup index.
Other Observations (not in diff)

These warnings are in incremental-only packages/kilo-memory/ changes that are not present in gh pr diff for this stacked PR, so they could not receive inline comments without hitting GitHub's diff-line restriction.

Files Reviewed (24 files)
  • packages/kilo-memory/src/capture/capture.ts
  • packages/kilo-memory/src/capture/diff.ts
  • packages/kilo-memory/src/capture/digest-text.ts
  • packages/kilo-memory/src/capture/ops.ts
  • packages/kilo-memory/src/capture/outcome.ts
  • packages/kilo-memory/src/capture/parse.ts
  • packages/kilo-memory/src/capture/plan.ts
  • packages/kilo-memory/src/capture/redact.ts - 1 issue
  • packages/kilo-memory/src/capture/reject.ts
  • packages/kilo-memory/src/memory-notice.ts
  • packages/kilo-memory/src/memory.ts
  • packages/kilo-memory/src/recall/budget.ts - 1 issue
  • packages/kilo-memory/src/recall/index-format.ts
  • packages/kilo-memory/src/recall/indexer.ts
  • packages/kilo-memory/src/recall/shared.ts
  • packages/kilo-memory/src/storage/markdown.ts
  • packages/kilo-memory/src/storage/sessions.ts
  • packages/kilo-memory/src/storage/sources.ts
  • packages/kilo-memory/src/storage/state.ts
  • packages/kilo-memory/src/text.ts
  • packages/kilo-memory/test/capture.test.ts
  • packages/kilo-memory/test/core.test.ts
  • packages/kilo-memory/test/markdown.test.ts
  • packages/kilo-memory/test/text.test.ts

Fix these issues in Kilo Cloud

Previous review (commit e0a734e)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-memory/src/capture/redact.ts 48 Bare user@host URLs now trip the secret detector, so harmless clone/remote URLs can no longer be saved into memory.
packages/kilo-memory/src/recall/budget.ts 60 The truncation note tells agents to use mode=typed, which cannot recover omitted session digests from a truncated startup index.
Other Observations (not in diff)

These warnings are in incremental-only packages/kilo-memory/ changes that are not present in gh pr diff for this stacked PR, so they could not receive inline comments without hitting GitHub's diff-line restriction.

Files Reviewed (24 files)
  • packages/kilo-memory/src/capture/capture.ts
  • packages/kilo-memory/src/capture/diff.ts
  • packages/kilo-memory/src/capture/digest-text.ts
  • packages/kilo-memory/src/capture/ops.ts
  • packages/kilo-memory/src/capture/outcome.ts
  • packages/kilo-memory/src/capture/parse.ts
  • packages/kilo-memory/src/capture/plan.ts
  • packages/kilo-memory/src/capture/redact.ts - 1 issue
  • packages/kilo-memory/src/capture/reject.ts
  • packages/kilo-memory/src/memory-notice.ts
  • packages/kilo-memory/src/memory.ts
  • packages/kilo-memory/src/recall/budget.ts - 1 issue
  • packages/kilo-memory/src/recall/index-format.ts
  • packages/kilo-memory/src/recall/indexer.ts
  • packages/kilo-memory/src/recall/shared.ts
  • packages/kilo-memory/src/storage/markdown.ts
  • packages/kilo-memory/src/storage/sessions.ts
  • packages/kilo-memory/src/storage/sources.ts
  • packages/kilo-memory/src/storage/state.ts
  • packages/kilo-memory/src/text.ts
  • packages/kilo-memory/test/capture.test.ts
  • packages/kilo-memory/test/core.test.ts
  • packages/kilo-memory/test/markdown.test.ts
  • packages/kilo-memory/test/text.test.ts

Fix these issues in Kilo Cloud

Previous review (commit 71882a3)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-memory/src/capture/redact.ts 48 Bare user@host URLs now trip the secret detector, so harmless clone/remote URLs can no longer be saved into memory.
packages/kilo-memory/src/recall/budget.ts 60 The truncation note tells agents to use mode=typed, which cannot recover omitted session digests from a truncated startup index.
Other Observations (not in diff)

These warnings are in incremental-only packages/kilo-memory/ changes that are not present in gh pr diff for this stacked PR, so they could not receive inline comments without hitting GitHub's diff-line restriction.

Files Reviewed (24 files)
  • packages/kilo-memory/src/capture/capture.ts
  • packages/kilo-memory/src/capture/diff.ts
  • packages/kilo-memory/src/capture/digest-text.ts
  • packages/kilo-memory/src/capture/ops.ts
  • packages/kilo-memory/src/capture/outcome.ts
  • packages/kilo-memory/src/capture/parse.ts
  • packages/kilo-memory/src/capture/plan.ts
  • packages/kilo-memory/src/capture/redact.ts - 1 issue
  • packages/kilo-memory/src/capture/reject.ts
  • packages/kilo-memory/src/memory-notice.ts
  • packages/kilo-memory/src/memory.ts
  • packages/kilo-memory/src/recall/budget.ts - 1 issue
  • packages/kilo-memory/src/recall/index-format.ts
  • packages/kilo-memory/src/recall/indexer.ts
  • packages/kilo-memory/src/recall/shared.ts
  • packages/kilo-memory/src/storage/markdown.ts
  • packages/kilo-memory/src/storage/sessions.ts
  • packages/kilo-memory/src/storage/sources.ts
  • packages/kilo-memory/src/storage/state.ts
  • packages/kilo-memory/src/text.ts
  • packages/kilo-memory/test/capture.test.ts
  • packages/kilo-memory/test/core.test.ts
  • packages/kilo-memory/test/markdown.test.ts
  • packages/kilo-memory/test/text.test.ts

Fix these issues in Kilo Cloud

Previous review (commit 5ec40fc)

Status: No Issues Found | Recommendation: Merge

All three previously flagged issues have been resolved in commit 5ec40fc88b:

  • Dead Effect.catch in system-prompt.ts — fixed by switching to Effect.tryPromise(() => …) overload
  • Instance context loss in service.ts bridge — fixed with InstanceState.bind wrapper
  • Permission rejection swallowing in memory-recall.ts — fixed with Effect.catchIf targeting only memory-domain errors
  • Service wrapper bypass in session/prompt.ts — fixed by extending SystemPrompt.Service.environment and routing through it
Files Reviewed (62 files)
  • .changeset/kilo-memory-cli.md
  • packages/opencode/package.json
  • packages/opencode/src/cli/cmd/tui/app.tsx
  • packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
  • packages/opencode/src/cli/cmd/tui/routes/session/index.tsx
  • packages/opencode/src/cli/cmd/tui/routes/session/permission.tsx
  • packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx
  • packages/opencode/src/config/config.ts
  • packages/opencode/src/effect/app-runtime.ts
  • packages/opencode/src/kilocode/agent/index.ts
  • packages/opencode/src/kilocode/cli/cmd/tui/component/dialog-memory.tsx
  • packages/opencode/src/kilocode/cli/cmd/tui/component/memory-sidebar.tsx
  • packages/opencode/src/kilocode/cli/cmd/tui/memory-command.ts
  • packages/opencode/src/kilocode/cli/cmd/tui/memory-events.ts
  • packages/opencode/src/kilocode/cli/cmd/tui/memory-meta.ts
  • packages/opencode/src/kilocode/memory/capture.ts
  • packages/opencode/src/kilocode/memory/config.ts
  • packages/opencode/src/kilocode/memory/errors.ts
  • packages/opencode/src/kilocode/memory/events.ts
  • packages/opencode/src/kilocode/memory/index.ts
  • packages/opencode/src/kilocode/memory/paths.ts
  • packages/opencode/src/kilocode/memory/service.ts
  • packages/opencode/src/kilocode/memory/timers.ts
  • packages/opencode/src/kilocode/memory/turn.ts
  • packages/opencode/src/kilocode/plugins/home-footer.tsx
  • packages/opencode/src/kilocode/server/httpapi/groups/memory.ts
  • packages/opencode/src/kilocode/server/httpapi/handlers/memory.ts
  • packages/opencode/src/kilocode/server/httpapi/server.ts
  • packages/opencode/src/kilocode/session/prompt.ts
  • packages/opencode/src/kilocode/skills/kilo-config.md
  • packages/opencode/src/kilocode/system-prompt.ts
  • packages/opencode/src/kilocode/tool/memory-recall.ts
  • packages/opencode/src/kilocode/tool/memory-recall.txt
  • packages/opencode/src/kilocode/tool/memory-save.ts
  • packages/opencode/src/kilocode/tool/memory-save.txt
  • packages/opencode/src/kilocode/tool/registry.ts
  • packages/opencode/src/server/routes/instance/httpapi/api.ts
  • packages/opencode/src/server/routes/instance/httpapi/server.ts
  • packages/opencode/src/session/prompt.ts
  • packages/opencode/src/session/system.ts
  • packages/opencode/src/tool/registry.ts
  • packages/opencode/test/config/config.test.ts
  • packages/opencode/test/kilocode/config/config.test.ts
  • packages/opencode/test/kilocode/memory/memory-capture.test.ts
  • packages/opencode/test/kilocode/memory/memory-command.test.ts
  • packages/opencode/test/kilocode/memory/memory-core.test.ts
  • packages/opencode/test/kilocode/memory/memory-recall-tool.test.ts
  • packages/opencode/test/kilocode/memory/memory-save-tool.test.ts
  • packages/opencode/test/kilocode/memory/tool-runtime.ts
  • packages/opencode/test/kilocode/server/httpapi-exercise-scenarios.ts
  • packages/opencode/test/kilocode/server/httpapi-memory.test.ts
  • packages/opencode/test/kilocode/server/httpapi-public.test.ts
  • packages/opencode/test/kilocode/session-compaction-cap.test.ts
  • packages/opencode/test/kilocode/session-prompt-compaction-safety.test.ts
  • packages/opencode/test/kilocode/session-prompt-permission-refresh.test.ts
  • packages/opencode/test/kilocode/tool-registry-indexing-import-failure.test.ts
  • packages/opencode/test/kilocode/tool-registry-indexing.test.ts
  • packages/opencode/test/kilocode/tool-registry-semantic-import-failure.test.ts
  • packages/opencode/test/session/prompt.test.ts
  • packages/opencode/test/session/snapshot-tool-race.test.ts
  • packages/opencode/test/tool/registry.test.ts
  • packages/sdk/js/src/v2/gen/sdk.gen.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts
  • packages/sdk/openapi.json

Fix these issues in Kilo Cloud


Reviewed by gpt-5.4-20260305 · 243,311 tokens

Review guidance: REVIEW.md from base branch johnnyeric/memory-core-safety

@johnnyeric johnnyeric force-pushed the johnnyeric/memory-cli-integration branch 2 times, most recently from 13cf5d9 to 5ec40fc Compare June 17, 2026 12:41
@johnnyeric johnnyeric changed the title fix(cli): add project memory integration feat(cli): add project memory integration Jun 17, 2026
@johnnyeric johnnyeric force-pushed the johnnyeric/memory-core-safety branch from 7194bf7 to e7e9efe Compare June 18, 2026 12:57
@johnnyeric johnnyeric force-pushed the johnnyeric/memory-cli-integration branch 4 times, most recently from e0a734e to 9713ad9 Compare June 18, 2026 18:51
@johnnyeric johnnyeric force-pushed the johnnyeric/memory-cli-integration branch from 9713ad9 to 794189b Compare June 18, 2026 18:57
@johnnyeric johnnyeric force-pushed the johnnyeric/memory-core-safety branch from e7e9efe to 0486646 Compare June 19, 2026 11:30

@catrielmuller catrielmuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void exit()
return true
}
// kilocode_change start - handle memory management as a harness action, not a chat prompt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to packages/opencode/src/kilocode/cli/cmd/tui/component/prompt/index.tsx

<Show when={duration()}>
<span style={{ fg: theme.textMuted }}> · {Locale.duration(duration())}</span>
</Show>
{/* kilocode_change start - show per-turn memory usage in the assistant footer */}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to packages/opencode/src/kilocode/cli/cmd/tui/routes/session/index.tsx

import { usePathFormatter } from "../../context/path-format"

type PermissionStage = "permission" | "always" | "reject"
// kilocode_change start - allow Kilo-owned permission renderers without per-permission shared branches

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to move this to packages/opencode/src/kilocode/cli/cmd/tui/routes/session/permission.tsx

}
})

// kilocode_change start - memory data directories do not need plugin dependency installs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integrate this with the config hooks on "packages/opencode/src/kilocode/config/config.ts"

Effect.forkDetach,
)
deps.push(dep)
// kilocode_change start - skip plugin package setup for memory-only .kilo data dirs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

)
}

function Memory(props: { api: TuiPluginApi }) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets keep the footer clean, move the status information to the sidebar.

yield* sessions.init()
yield* kilo.init()
yield* MemoryLifecycle.subscribe({ bus, sessions, summary, provider, memory })
// kilocode_change start - invalidate enabled cache on every memory state mutation (properties.directory holds the memory root)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the kilo markers on the kilo owned files


// kilocode_change start - persistently prune stale tool outputs when payload is already large
const [skills, env, instructions] = yield* Effect.all([
const enabled = yield* KiloSessionPrompt.memoryToolEnabled({ ctx }) // kilocode_change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to "packages/opencode/src/kilocode/session/prompt.ts"

const match = text?.match(/^gitdir:\s*(.+)$/m)
if (!match?.[1]) return dir
const git = path.resolve(dir, match[1])
return checkout(common(git)) ?? dir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we validate that this gitdir belongs to the current checkout before using it as the memory identity? A workspace-controlled .git file can point at another local checkout, which would make this workspace load and expose Kilo memory from that other project.

})
if (!state.enabled || !state.capture.turnClose) return yield* skip("disabled")
const now = Date.now()
const messages = yield* input.sessions.messages({ sessionID: input.sessionID })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use a bounded message window instead of sessions.messages without limit? That path pages the whole transcript, so turn-close memory capture rereads long session history every turn.

const completed = !input.reason || input.reason === "completed"
// Echo = short lookup answered from memory with no file changes. Long recall-assisted answers
// (research, investigations) carry new content and must still be digested.
const echo = !durable && assistant.length < 1200 && recalledMemory(turn)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this echo check include all assistant steps for the current user turn? latest() returns the final answer, but kilo_memory_recall can run in an earlier assistant step, so recalled facts can be saved back as new memory.

skipped.push(rejected)
return false
}
const source = duplicate(`${item.key} ${item.text}`, input.items)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this skip valid memory before the file/section-aware applier sees it? This token-overlap check runs across all stored items, so a correction and a project fact with similar words can be treated as duplicates even though MemoryOperations.apply would keep them separate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants